{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dendron import *\n",
    "from dendron.actions import PipelineActionConfig, PipelineAction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are going to create a behavior for sentiment analysis using Hugging Face's pipeline abstraction. We define the task and then some _blackboard keys_ for handling input and output. Blackboards are key-value stores accessible on a per-tree basis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cfg = PipelineActionConfig(\n",
    "    task_name=\"sentiment-analysis\",\n",
    "    model = \"distilbert-base-uncased-finetuned-sst-2-english\",\n",
    "    input_key = \"sentiment/in\",\n",
    "    output_key = \"sentiment/out\",\n",
    "    device = \"cuda\",\n",
    ")\n",
    "\n",
    "node = PipelineAction(\"sentiment\", cfg)\n",
    "tree = BehaviorTree(\"sentiment-tree\", node)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tree.blackboard[\"sentiment/in\"] = \"Office building owners are losing hope that occupancy rates will rebound soon.\"\n",
    "status = tree.tick_once()\n",
    "if status == NodeStatus.SUCCESS:\n",
    "    print(tree.blackboard_get(\"sentiment/out\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tree.blackboard.set_print_len(32)\n",
    "print(tree.blackboard)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
